<!--
 * @Description: 描述信息
 * @Version: 版本号
 * @Author: xuebao
 * @Date: 2023-12-04 15:32:13
 * @LastEditors: renmengxue
 * @LastEditTime: 2023-12-08 16:53:28
-->
<template>
  <div class="row">
    <div v-for="column in columnList" :key="column._id" class="col-4 mb-4">
      <div class="card h-100 shadow-sm">
        <div class="card-body text-center">
          <img :src="column.avatar && column.avatar.url" :alt="column.title"
            class="rounded-circle border border-light w-25 my-3">
          <h5 class="card-title">{{ column.title }}</h5>
          <p class="card-text text-left">{{ column.description }}</p>
          <!-- <router-link class="btn btn-outline-primary" :to="{
            name: 'column',
            params: {
              id: column.id
            }
          }">进入专栏</router-link> -->
          <router-link class="btn btn-outline-primary" :to="`/column/${column._id}`">进入专栏</router-link>
        </div>
      </div>
    </div>

  </div>
</template>
<script lang="ts">

import { PropType, defineComponent, computed } from 'vue'
import { ColumnProps } from '../store'
export default defineComponent({
  name: 'ColumnList',
  props: {
    list: {
      type: Array as PropType<ColumnProps[]>,
      required: true
    }
  },
  setup(props) {
    const columnList = computed(() => {
      return props.list.map((column) => {
        // 如果没有传头像就设置一个默认的头像
        if (!column.avatar) {
          column.avatar = {
            url: require('../assets/column.jpg')
          }
        }
        return column
      })
    })
    return {
      columnList
    }
  }

})
</script>
